package com.linran.javaweb.vo;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class PageVo {
    /**
     * 页码, 从1开始
     */
    private int pageNo;
    /**
     * 页面大小
     */
    private int pageSize;
    /**
     * 起始行
     */
    private int startRow;
    /**
     * 总数
     */
    private long total;
    /**
     * 总页数
     */
    private int pages;

    public PageVo(int pageNo, int pageSize, long total) {
        this.pageSize = pageSize;
        this.total = total <= 0 ? 0 : total;
        this.pages = total == 0 ? 0 : (int) Math.ceil(total * 1.00 / pageSize);
        this.pageNo = Math.min(pageNo, pages);
        this.startRow = pages == 0 ? 0 : (pageNo - 1) * pageSize + 1;
    }
}
